﻿using System;
using System.Collections.Generic;
using System.Text;

namespace gChartSharp
{
    /// <summary>
    /// http://code.google.com/apis/chart/#bar_width
    /// </summary>
    public class BarStyleParam : IChartParam
    {
        /// <summary>
        /// The name of the API parameter
        /// </summary>
        public string Name { get { return "chbh"; } }


        /// <summary>
        /// Bar width in pixels
        /// </summary>
        public int BarWidth { get; set; }


        /// <summary>
        /// Space between bars in pixels
        /// </summary>
        public int? SpaceBetweenBars { get; set; }


        /// <summary>
        /// Space between bar groups in pixels
        /// </summary>
        public int? SpaceBetweenBarGroups { get; set; }


        /// <summary>
        /// Default constructor
        /// </summary>
        public BarStyleParam() { }


        /// <summary>
        /// Constructor that iniitalizes minimum number of properties
        /// </summary>
        /// <param name="barWidth"></param>
        public BarStyleParam(int barWidth) { this.BarWidth = BarWidth; }
                
        
        /// <summary>
        /// Render the text of the API
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(String.Format("&{0}={1}", this.Name, this.BarWidth));

            if (this.SpaceBetweenBars != null)
                sb.Append(String.Format(",{0}", this.SpaceBetweenBars));

            if (this.SpaceBetweenBarGroups != null)
                sb.Append(String.Format(",{0}", this.SpaceBetweenBarGroups));

            return sb.ToString();
        }
    }
}
